package com.xrh.xdemo.api.request.queryRequest;

import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class SysUserQueryRequest {

	@ApiModelProperty("关键词")
	private String keywords;
	
    /**主键id */
	@ApiModelProperty("主键id")
	private Long id;
	
	@ApiModelProperty("角色id")
	private Long sysRoleId;
	
	@ApiModelProperty("是否已绑定角色id")
	private Boolean bindFlag;

	/**账号/用户名 */
	@ApiModelProperty("账号/用户名")
	private String account;

	/**用户姓名 */
	@ApiModelProperty("用户姓名")
	private String userName;

	/**邮箱 */
	@ApiModelProperty("邮箱")
	private String email;

	/**手机号 */
	@ApiModelProperty("手机号")
	private String phoneNumber;

	/**是否禁用(0:禁用 , 1: 启用) */
	@ApiModelProperty("是否禁用(0:禁用 , 1: 启用)")
	private Integer enable;

	/**性别 */
	@ApiModelProperty("性别")
	private String gender;

	/**生日 */
	@ApiModelProperty("生日")
	private Date birthdayStart;

	/**生日 */
	@ApiModelProperty("生日")
	private Date birthdayEnd;

	/**上次登录时间 */
	@ApiModelProperty("上次登录时间")
	private Date lastLoginTimeStart;

	/**上次登录时间 */
	@ApiModelProperty("上次登录时间")
	private Date lastLoginTimeEnd;

    @ApiModelProperty(value = "当前页码" )
    private Integer pageNum = 1;

    @ApiModelProperty(value = "每页数量" )
    private Integer pageSize = 10;

	 //获取查询条件,注释部分要自己填写
	public <T> QueryWrapper<T> createQuery() {
			
		QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
		
		//关键词检索
		if(StrUtil.isNotBlank(keywords)) {
			queryWrapper.and(w->w.like("account", keywords).or().like("user_name", keywords).or().like("phone_number", keywords));
		}
		
		if(id != null)
			queryWrapper.eq("id", id);

		if(StrUtil.isNotBlank(account))
			queryWrapper.eq("account", account);

		if(StrUtil.isNotBlank(userName))
			queryWrapper.eq("user_name", userName);

		if(StrUtil.isNotBlank(email))
			queryWrapper.eq("email", email);

		if(StrUtil.isNotBlank(phoneNumber))
			queryWrapper.eq("phone_number", phoneNumber);

		if(enable != null)
			queryWrapper.eq("enable", enable);

		if(StrUtil.isNotBlank(gender))
			queryWrapper.eq("gender", gender);

		if(birthdayStart != null)
			queryWrapper.ge("birthday", birthdayStart);

		if(birthdayEnd != null)
			queryWrapper.le("birthday", birthdayEnd);

		if(lastLoginTimeStart != null)
			queryWrapper.ge("last_login_time", lastLoginTimeStart);

		if(lastLoginTimeEnd != null)
			queryWrapper.le("last_login_time", lastLoginTimeEnd);

		queryWrapper.orderByDesc("id");
		
		return queryWrapper;
	}
		
	//获取分页
   public <T> Page<T> createPage(){
	   return new Page<>(pageNum , pageSize);
   }
	   
}
